<template>
  <div class="box">
    <!-- 高级查询选择查询字段 查询的数组  列定义 请求接口地址 获取列表时默认的请求参数 编辑 ref绑定的名字-->
    <RenderTable
      :superQueryFieldList="superQueryFieldList"
      :queryParamArr="queryParamArr"
      :defColumns="defColumns"
      :url="url"
      :defaultParams="defaultParams"
      @handleEdit="handleEdit"
      ref="renderTable"
    >
      <div slot="btn" style="display: inline-block; margin-right: 10px">
        <p-button type="primary" @click="showAddModal">新增</p-button>
      </div>
      <template v-slot:action="{ record }">
        <a @click="handleEdit(record)" style="margin-right: 10px">编辑</a>
        <p-popconfirm
          title="确定删除吗?"
          @confirm="() => $refs.renderTable.handleDelete(record.id)"
        >
          <a>删除</a>
        </p-popconfirm>
      </template>
    </RenderTable>

    <NewProductSimilarityModal
      ref="newProductSimilarityModal"
      @handleSuccess="handleSuccess"
    ></NewProductSimilarityModal>
  </div>
</template>

<script type="text/javascript">
import RenderTable from '@/components/renderTable'
import NewProductSimilarityModal from './modules/newProductSimilarityModal.vue'
// 时间戳转换格式
import { timestampToDatetime } from '@/utils/util'
const superQueryFieldList = [
  {
    value: 'weightRatio',
    text: '车间',
    type: 'String',
  },
  {
    value: 'weightRatio',
    text: '班组',
    type: 'String',
  },
  {
    value: 'weightRatio',
    text: '首线数量',
    type: 'String',
  },
  {
    value: 'weightRatio',
    text: '系数',
    type: 'String',
  },
  {
    value: 'remark',
    text: '备注',
    type: 'String',
  },
]
export default {
  data() {
    return {
      superQueryFieldList,
      queryParamArr: [
        {
          label: '项目名称',
          placeholder: '请输入项目名称',
          type: 'input',
          key: 'project',
          value: '',
        },
      ],
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (t, r, index) => {
            return parseInt(index) + 1
          },
        },
        {
          title: '新产品编码',
          align: 'center',
          dataIndex: 'newmcode',
        },
        {
          title: '新产品描述',
          align: 'center',
          dataIndex: 'newmname',
        },
        {
          title: '相似产品编码',
          align: 'center',
          dataIndex: 'similarityMcode',
        },
        {
          title: '相似产品描述',
          align: 'center',
          dataIndex: 'similarityMname',
        },
        {
          title: '相似度得分',
          align: 'center',
          dataIndex: 'similarityScore',
        },
        {
          title: '是否有激励',
          align: 'center',
          dataIndex: 'hasStimulate',
          scopedSlots: { customRender: 'hasStimulate' },
        },
        {
          title: '是否到货检天线',
          align: 'center',
          dataIndex: 'isArrival',
          scopedSlots: { customRender: 'isArrival' },
        },
        {
          title: '维护人',
          align: 'center',
          dataIndex: 'createName',
        },
        {
          title: '维护者工号',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '修改人',
          align: 'center',
          dataIndex: 'updateName',
        },
        {
          title: '修改人工号',
          align: 'center',
          dataIndex: 'updateBy',
        },
        {
          title: '修改时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: (t, r, index) => {
            return timestampToDatetime(t)
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      defaultParams: {},
      url: {
        list: '/mes-manpower/mesHrNewmSimilarityCoefficient/list',
        delete: '/mes-manpower/mesHrNewmSimilarityCoefficient',
      },

      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
      },
    }
  },
  mounted() {},
  methods: {
    // 编辑的弹框,要传这一行的数据过去
    handleEdit(record) {
      this.$refs.newProductSimilarityModal.showModal(record)
    },
    // 显示新增弹窗
    showAddModal() {
      this.$refs.newProductSimilarityModal.showModal()
    },
    // 新增或者编辑点击确定调用查询的方法
    handleSuccess() {
      this.$refs.renderTable.loadData()
    },
  },
  components: {
    RenderTable,
    NewProductSimilarityModal,
  },
}
</script>

<style lang="less" scoped>
</style>
